package com.zkj.controller.user;


import com.zkj.dto.OrdersPaymentDTO;
import com.zkj.dto.OrdersSubmitDTO;
import com.zkj.vo.OrderPaymentVO;
import com.zkj.vo.OrderSubmitVO;
import com.zkj.result.Result;
import com.zkj.service.IOrdersService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 订单表 前端控制器
 * </p>
 *
 * @author zkj
 * @since 2024-10-16
 */
@RestController("userOrdersController")
@RequestMapping("/user/order")
@Slf4j
@Api(tags = "用户订单接口")
public class OrdersController {

    @Autowired
    private IOrdersService ordersService;

    /**
     * 提交订单 - 用户下单
     *
     * @param ordersSubmitDTO
     * @return
     */
    @PostMapping("/submit")
    @ApiOperation(value = "用户下单 - 提交订单")
    public Result<OrderSubmitVO> submit(@RequestBody OrdersSubmitDTO ordersSubmitDTO) {
        log.info("用户下单 - 提交订单, 订单信息: {}", ordersSubmitDTO);
        OrderSubmitVO submitVO = ordersService.submitOrder(ordersSubmitDTO);
        return Result.success(submitVO);
    }


    /**
     * 订单支付
     *
     * @param ordersPaymentDTO
     * @return
     */
    @PutMapping("/payment")
    @ApiOperation("订单支付")
    public Result<OrderPaymentVO> payment(@RequestBody OrdersPaymentDTO ordersPaymentDTO) throws Exception {
        log.info("订单支付：{}", ordersPaymentDTO);
        OrderPaymentVO orderPaymentVO = ordersService.payment(ordersPaymentDTO);
        log.info("生成预支付交易单：{}", orderPaymentVO);
        return Result.success(orderPaymentVO);
    }

}
